import numpy as np
import pandas as pd
import pyecharts

class ChipotleAna:

    path = 'C:/Users/Administrator/pandas_exercises-c1/01_Getting_&_Knowing_Your_Data/Chipotle/chipotle.csv'


    def __init__(self):

        #self.path = 'C:/Users/Administrator/pandas_exercises-c1/01_Getting_&_Knowing_Your_Data/Chipotle/chipotle.csv'

        self.df = pd.read_csv(self.path, sep = '\t')


    def echarts_bar(self, series, bar_name = 'test', name = 'test_name' ):

        bar = pyecharts.Bar(bar_name)

        asix0 = series.index

        asix1 = series.values.ravel()

        bar.add(name, asix0, asix1, is_label_show=True, is_datazoom_show=True)

        return bar

    

    def how_many_are_sold_per_item(self):#每个商品卖了多少件

        count_info = self.df.groupby('item_name').sum()

        count_info = count_info.drop('order_id', axis = 1)

        return count_info

    def bar_how_many_are_sold_per_item(self):

        return self.echarts_bar(self.how_many_are_sold_per_item(),bar_name = '每种商品卖出个数')


    def how_much_are_sold_per_item(self):#第个商品卖了多少钱

        x = self.df.quantity*(self.df.item_price.str.replace('$','').astype('float64'))
        
        df1 = self.df.copy()
        
        df1['price'] = round(x, 2)
        
        df1 = df1.groupby('item_name').sum()
        
        return round(df1['price'], 2)

    def bar_how_much_are_sold_per_item(self):

        return self.echarts_bar(self.how_much_are_sold_per_item(), bar_name = '每种商品总收入')

































    


        
